/*
 * Copyright (c) 2010 Richard Hawkins
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.googlecode.android_apps_admin;

import com.googlecode.android_apps_admin.app.AndroidAppsAdminActivity;
import android.content.Intent;
import android.os.Bundle;

/**
 * Entry point for the application.  This activity is responsible for displaying the splash screen,
 * if it is to be displayed.  It is also responsible for checking whether a default domain is set.
 * If a default domain is set, the account manager activity will be skipped and the domain will
 * be loaded directly.  If the default domain is not set, then the account manager will be loaded
 * so the appropriate domain can be selected.
 *
 * @author Richard Hawkins (imbecyclic@gmail.com)
 */
public class Main extends AndroidAppsAdminActivity {

  /** 
   * Called when the activity is first created. 
   * 
   * @param savedInstanceState
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    log("Main:onCreate()");
    super.onCreate(savedInstanceState);
    Intent defaultIntent; 
    String defaultDomain;

    if (shouldDisplaySplashScreen()) {
      // TODO(rhawkins): Display Splash Screen.
    }

    defaultIntent = new Intent();
    defaultDomain = getDefaultDomain();

    if (defaultDomain == null) {
      log("Loading Account Manager");
      defaultIntent.setClassName(AccountManager.CONTEXT, AccountManager.CLASSNAME);
    } else {
      log("Loading Cpanel for default domain.");
      defaultIntent.setClassName(AndroidAppsAdmin.CONTEXT, AndroidAppsAdmin.CLASSNAME);
      // TODO(rhawkins): pass default domain over.
      //defaultIntent.putExtra("com.googlecode.android_apps_admin.SomeVarName", defaultDomain);
    } 

    startActivity(defaultIntent);
    finish();
  }

  /**
   * Checks the application's settings to determine if the splash screen should be displayed.
   *
   * @return true if the splash screen is to be displayed, false otherwise.
   */
  protected boolean shouldDisplaySplashScreen() {
    log("Main:shouldDisplaySplashScreen()");
    boolean result = true;

    // TODO(rhawkins): implement method.

    return result; 
  }

  /**
   * Checks the application's settings to determin if a default domain has been set.
   * If a default domain has been set, the application will return a String containing the domain.
   * In the event that a default domain has not been set, null will be returned.:w
   *
   * @return A String containing the default domain if one is set, null is returned otherwise.
   */
  protected String getDefaultDomain() {
    log("Main:getDefaultDomain()");
    String result = null;

    // TODO(rhawkins): implement method.

    return result;
  }
}

